package com.itboye.ihomebank.responsitory;

import com.google.gson.reflect.TypeToken;
import com.itboye.ihomebank.base.BaseNetRepository;
import com.itboye.ihomebank.base.ICompleteListener;
import com.itboye.ihomebank.bean.ElectricMeterBean;
import com.itboye.ihomebank.bean.FeeDailyBean;
import com.itboye.ihomebank.bean.FeeMonthBean;
import com.itboye.ihomebank.bean.MeterDetailBean;
import com.itboye.ihomebank.interfaces.IElectricMeterInterface;
import com.itboye.ihomebank.net.BaseErrorListener;
import com.itboye.ihomebank.net.BaseSuccessReqListener;
import com.itboye.ihomebank.net.ByJsonRequest;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/8/31 0031.
 */

public class ElectricMeterRepository extends BaseNetRepository implements IElectricMeterInterface {

    String api = "100";
    String api1="101";
    String queryEmeter = "BY_Emeter_query";// 电表分页
    String queryMyEmeter= "BY_Emeter_myAddress";//我的电表
    String emeterDetail = "BY_Emeter_detail";// 电表详情
    String emeterPullOff = "BY_Emeter_switchFlag";// 电表合闸
    String emeterEditField ="BY_Emeter_editField";//电表单属性更改
    String emeterEdit ="BY_Emeter_edit";//电表整改
    String emeterSyn ="AM_Emeter_sync";//电表整改
    String feeMonth = "BY_Emeter_feeMonth"; // 电费/充值 每月
    String feeDaily = "BY_Emeter_feeDaily"; // 电费 每天

    public ElectricMeterRepository(ICompleteListener iCompleteListener) {
        super(iCompleteListener);
    }

    @Override
    public void queryEmeter(String field, String order, String page, String size, String kword) {

        // TODO Auto-generated method stub
        Type type = new TypeToken<List<ElectricMeterBean>>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("field", field);
        map.put("order", order);
        map.put("page", page);
        map.put("size", size);
        map.put("kword", kword);

        (new ByJsonRequest.Builder<List<ElectricMeterBean>>())
                .setTypeVerParamsAndReturnClass(queryEmeter, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<List<ElectricMeterBean>>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void queryMyEmeter(String uid, String kword,String sort) {

        // TODO Auto-generated method stub
        Type type = new TypeToken<List<ElectricMeterBean>>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("kword", kword);
        map.put("sort", sort);

        (new ByJsonRequest.Builder<List<ElectricMeterBean>>())
                .setTypeVerParamsAndReturnClass(queryMyEmeter, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<List<ElectricMeterBean>>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void emeterDetaile(String uid, String eid) {

        // TODO Auto-generated method stub
        Type type = new TypeToken<MeterDetailBean>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("eid", eid);

        (new ByJsonRequest.Builder<MeterDetailBean>())
                .setTypeVerParamsAndReturnClass(emeterDetail, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<MeterDetailBean>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void bindHouseNo(String uid, String eid, String house_no, String house_people) {

    }

    @Override
    public void unbindHouseNo(String uid, String eid, String house_no) {

    }

    @Override
    public void emeterPullOff(String uid, String eid, String op_type) {

        // TODO Auto-generated method stub
        Type type = new TypeToken<List<ElectricMeterBean>>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("eid", eid);
        map.put("op_type", op_type);

        (new ByJsonRequest.Builder<List<ElectricMeterBean>>())
                .setTypeVerParamsAndReturnClass(emeterPullOff, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<List<ElectricMeterBean>>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void emeterEditField(String uid, String eid, String field, String value) {

        // TODO Auto-generated method stub
        Type type = new TypeToken<List<ElectricMeterBean>>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("eid", eid);
        map.put("field", field);
        map.put("value", value);

        (new ByJsonRequest.Builder<List<ElectricMeterBean>>())
                .setTypeVerParamsAndReturnClass(emeterEditField, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<List<ElectricMeterBean>>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void emeterEdit(String uid, String eid, String name, String price, String fee_type, String house_people) {

        // TODO Auto-generated method stub
        Type type = new TypeToken<List<ElectricMeterBean>>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("eid", eid);
        map.put("name", name);
        map.put("price", price);
        map.put("fee_type", fee_type);
        map.put("house_people", house_people);

        (new ByJsonRequest.Builder<List<ElectricMeterBean>>())
                .setTypeVerParamsAndReturnClass(emeterEdit, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<List<ElectricMeterBean>>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();

    }

    @Override
    public void emeterSyn(String time, String sync) {

        // TODO Auto-generated method stub
        Type type = new TypeToken<List<ElectricMeterBean>>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("time", time);
        map.put("sync", sync);

        (new ByJsonRequest.Builder<List<ElectricMeterBean>>())
                .setTypeVerParamsAndReturnClass(emeterSyn, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<List<ElectricMeterBean>>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void feeMonth(String uid, String start, String end, String fresh) {

        // TODO Auto-generated method stub
        Type type = new TypeToken<List<FeeMonthBean>>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("start", start);
        map.put("end", end);
        map.put("fresh", fresh);

        (new ByJsonRequest.Builder<List<FeeMonthBean>>())
                .setTypeVerParamsAndReturnClass(feeMonth, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<List<FeeMonthBean>>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void feeDaily(String uid, String aid,String start, String end, String fresh) {

        Type type = new TypeToken<List<FeeDailyBean>>() {
        }.getType();
        String apiVer = api1;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("aid",aid);
        map.put("start", start);
        map.put("end", end);
        map.put("fresh", fresh);

        (new ByJsonRequest.Builder<List<FeeDailyBean>>())
                .setTypeVerParamsAndReturnClass(feeDaily, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<List<FeeDailyBean>>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }
}
